package StudyCode.summary.mycollection;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ChecksIfTheSpecifiedCollectionarrayiteratorIsEmpty {

	public static boolean sizeIsEmpty(Object object) {
		if (object instanceof Collection) {
			return ((Collection<?>) object).isEmpty();
		} else if (object instanceof Map) {
			return ((Map<?, ?>) object).isEmpty();
		} else if (object instanceof Object[]) {
			return ((Object[]) object).length == 0;
		} else if (object instanceof Iterator) {
			return !((Iterator<?>) object).hasNext();
		} else if (object instanceof Enumeration) {
			return !((Enumeration<?>) object).hasMoreElements();
		} else if (object == null) {
			throw new IllegalArgumentException("不支持对象类型: null");
		} else {
			try {
				return Array.getLength(object) == 0;
			} catch (IllegalArgumentException ex) {
				throw new IllegalArgumentException(
						"不支持对象类型: " + object.getClass().getName());
			}
		}
	}

}
